package com.qianying.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianying.comment.CommonResult;
import com.qianying.entity.AcceptanceMethod;
import com.qianying.service.AcceptanceMethodService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 验收方式控制器
 * 提供验收方式的HTTP接口，处理前端请求
 */
@RestController
@RequestMapping("/admin/acceptanceMethod")
@Tag(name = "验收方式(收方式管理)", description = "验收方式信息的增删改查接口")
public class AcceptanceMethodController {

    @Autowired
    private AcceptanceMethodService acceptanceMethodService;

    /**
     * 分页查询验收方式列表
     *
     * @param current    页码
     * @param size       每页条数
     * @param methodName 验收方式名称（模糊查询）
     * @return 分页结果
     */
    @GetMapping("/getPage")
    @Operation(
            summary = "分页查询验收方式列表",
            description = "支持按验收方式名称模糊查询，返回分页数据",
            parameters = {
                    @Parameter(name = "current", description = "页码", example = "1"),
                    @Parameter(name = "size", description = "每页条数", example = "10"),
                    @Parameter(name = "methodName", description = "验收方式名称（模糊查询）", example = "纸质手签")
            }
    )
    public CommonResult<IPage<AcceptanceMethod>> getPage(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String methodName) {
        Page<AcceptanceMethod> page = new Page<>(current, size);
        return acceptanceMethodService.getPage(page, methodName);
    }

    /**
     * 根据ID查询验收方式详情
     *
     * @param id 主键ID
     * @return 验收方式详情
     */
    @GetMapping("/getById")
    @Operation(
            summary = "查询验收方式详情",
            description = "通过ID获取验收方式的完整信息",
            parameters = {
                    @Parameter(name = "id", description = "主键ID", required = true, example = "1")
            }
    )
    public CommonResult<AcceptanceMethod> getById(@RequestParam Long id) {
        return acceptanceMethodService.getById(id);
    }

    /**
     * 新增验收方式
     *
     * @param acceptanceMethod 验收方式信息（ID需为空）
     * @return 操作结果
     */
    @PostMapping("/saveMethod")
    @Operation(
            summary = "新增验收方式",
            description = "创建新的验收方式记录，验收方式名称为必填项，ID必须为空",
            parameters = {
                    @Parameter(name = "methodName", description = "验收方式名称", required = true, example = "纸质手签"),
                    @Parameter(name = "methodCode", description = "验收方式代号", example = "PAPER_SIGN"),
                    @Parameter(name = "description", description = "验收方式说明", example = "店铺打印资料手工签字，师傅上传资料照片")
            }
    )
    public CommonResult<?> saveMethod(@RequestBody AcceptanceMethod acceptanceMethod) {
        return acceptanceMethodService.saveMethod(acceptanceMethod);
    }

    /**
     * 更新验收方式
     *
     * @param acceptanceMethod 验收方式信息（需包含ID）
     * @return 操作结果
     */
    @PostMapping("/updateMethod")
    @Operation(
            summary = "更新验收方式",
            description = "修改已有验收方式信息，必须包含ID和验收方式名称",
            parameters = {
                    @Parameter(name = "id", description = "主键ID", required = true, example = "1"),
                    @Parameter(name = "methodName", description = "验收方式名称", required = true, example = "纸质手签"),
                    @Parameter(name = "methodCode", description = "验收方式代号", example = "PAPER_SIGN"),
                    @Parameter(name = "description", description = "验收方式说明", example = "店铺打印资料手工签字，师傅上传资料照片")
            }
    )
    public CommonResult<?> updateMethod(@RequestBody AcceptanceMethod acceptanceMethod) {
        return acceptanceMethodService.updateMethod(acceptanceMethod);
    }

    /**
     * 根据ID删除验收方式
     *
     * @param id 主键ID
     * @return 操作结果
     */
    @PostMapping("/removeById")
    @Operation(
            summary = "删除验收方式",
            description = "通过ID删除指定的验收方式记录",
            parameters = {
                    @Parameter(name = "id", description = "主键ID", required = true, example = "1")
            }
    )
    public CommonResult<?> removeById(@RequestParam Long id) {
        return acceptanceMethodService.removeById(id);
    }

    /**
     * 查询所有验收方式（不分页）
     *
     * @return 验收方式列表
     */
    @GetMapping("/getAll")
    @Operation(
            summary = "查询所有验收方式",
            description = "返回所有验收方式列表，适用于下拉选择等场景",
            parameters = {}
    )
    public CommonResult<?> getAll() {
        return acceptanceMethodService.getAll();
    }
}
